package com.itbaima.csmall.commons.restful;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * <p>JsonPage</p>
 *
 * @author Chen
 * @since 2023/2/24 15:37:37
 */
@Data
public class JsonPage<T> implements Serializable {

    private static final long serialVersionUID = 1623608360926140274L;
    /*
     * 可以添加其他有必要的分页信息属性
     */
    @ApiModelProperty(value = "当前页码", name = "pageNum")
    private Integer pageNum;
    @ApiModelProperty(value = "每页条数", name = "pageSize")
    private Integer pageSize;
    @ApiModelProperty(value = "总条数", name = "totalCount")
    private Long totalCount;
    @ApiModelProperty(value = "总页数", name = "totalPages")
    private Integer totalPages;
    @ApiModelProperty(value = "分页数据", name = "list")
    private List<T> list;

    public static <T> JsonPage<T> restPage(PageInfo<T> pageInfo) {
        JsonPage<T> jsonPage = new JsonPage<>();
        jsonPage.setTotalPages(pageInfo.getPages());
        jsonPage.setTotalCount(pageInfo.getTotal());
        jsonPage.setPageNum(pageInfo.getPageNum());
        jsonPage.setPageSize(pageInfo.getPageSize());
        jsonPage.setList(pageInfo.getList());
        return jsonPage;
    }

}
